1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : style/classes/class.style.inc.php
5 : - Modulgruppe: Style
6 : - Beschreibung: Anzeige und Auswahl der möglichen eStudy-Styles
7 : - Version: 0.5 07/12/08
8 : - Autor(en): George Parks Davie <killerg@gmx.net>
9 : Sebastian Walisko <sebastian@walisko.org>
10 : Markus Keim <markus.keim@mni.fh-giessen.de>
11 : Christoph Lhotak <paul.c.lhotak@mni.fh-giessen.de>
12 : +---------------------------------------------------------------------------+
13 : This program is free software; you can redistribute it and/or
14 : modify it under the terms of the GNU General Public License
15 : as published by the Free Software Foundation; either version 2
16 : of the License, or any later version.
17 : +---------------------------------------------------------------------------+
18 : This program is distributed in the hope that it will be useful,
19 : but WITHOUT ANY WARRANTY; without even the implied warranty of
20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 : GNU General Public License for more details.
22 : You should have received a copy of the GNU General Public License
23 : along with this program; if not, write to the Free Software
24 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 : +--------------------------------------------------------------------------*/
26 : /**
27 : * In dieser Datei wird die Klasse Style implementiert.
28 : * @package eStudy.Style
29 : * @version 0.4 03/01/07
30 : * @author George Parks Davie <killerg@gmx.net>
31 : * @author Sebastian Walisko <sebastian@walisko.org>
32 : * @author Markus Keim <markus.keim@mni.fh-giessen.de>
33 : */
34 1 : class Style {
35 :
36 : /**
37 : * Sucht alle Style Templates im Ordner style und gibt sie zurück
38 : * Update 07/12/08 Neues Feld im Array "Anzahl"
39 : *
40 : * @access public
41 : * @return array Infos zu verfügbaren Styles
42 : */
43 : function getStyleTemplates() {
44 0 : global $db, $EZSQL_ERROR;
45 0 : $StyleDir = PATH_TO_ROOT."style/";
46 0 : $StylesData = array();
47 0 : $dirCnt = 0;
48 0 : $styleDir = array();
49 0 : $dir = opendir($StyleDir);
50 0 : while ($file_name = readdir($dir)) { // style directories suchen
51 0 : $isDir = $StyleDir.$file_name;
52 0 : if (is_dir($isDir) && $file_name != "." && $file_name != ".." && $file_name != "CVS" && $file_name != "classes") {
53 0 : $styleDirs[] = $isDir;
54 0 : }
55 0 : }
56 0 : closedir($dir);
57 0 : sort($styleDirs, SORT_STRING);
58 0 : foreach($styleDirs as $dir) {
59 0 : $aboutcnt = 0;
60 0 : if (file_exists($dir."/_about.txt")) {
61 0 : $afile = @fopen($dir."/_about.txt", "r"); //suchen der _about.txt
62 0 : if ($afile) {
63 0 : $StylesData[$dirCnt][0] = substr(strrchr($dir, "/"), 1);
64 0 : while (!feof($afile)) {
65 0 : $row = fgetss($afile, 200); //read 200 character of line without html php...
66 0 : if (($row{0} != "#") && (strlen(trim($row{0})) > 0))
67 0 : $StylesData[$dirCnt][++$aboutcnt] = substr($row, 1, (strlen(trim($row)) -2 ));
68 0 : }
69 0 : fclose($afile);
70 : /* Feld "Anzahl" im Array hinzufuegen das die Anzahl der Benutzungen angibt */
71 0 : $StylesData[$dirCnt]["Anzahl"] = $db->get_var("SELECT count(*) AS Summe FROM user WHERE styletemplate = '". Data::toMysql($StylesData[$dirCnt][0])."'" );
72 0 : $dirCnt++;
73 0 : }
74 0 : }
75 0 : }
76 :
77 0 : return $StylesData;
78 : }
79 : /**
80 : * Listet alle Style Templates auf und stellt sie zur Auswahl bereit
81 : * Update 07/12/08 Sortiert ausserdem nach Anzahl der Nutzung
82 : * @access public
83 : * @return void
84 : */
85 : function listStyleTemplates() {
86 0 : global $db, $settings;
87 0 : $StylesData = Style::getStyleTemplates();
88 : /* Array nach der "Anzahl" Spalte sortieren */
89 0 : $StylesData = Style::sortiereArray($StylesData);
90 : /* Wieviele User haben noch gar keinen Style gewaehlt? */
91 0 : $basicUser = $db->get_var("SELECT count(*) AS Summe FROM user WHERE styletemplate is NULL" );
92 0 : $basicUser = $basicUser + $db->get_var("SELECT count(*) AS Summe FROM user WHERE styletemplate = ''" );
93 : /* Wieviele Styles insgesamt? */
94 0 : $count = count($StylesData);
95 : /* Wie oft wurde ueberhaupt ein Style gew�hlt und nicht einfach der Standard benutzt? */
96 0 : $anzahl = 0;
97 0 : foreach($StylesData as $sd){
98 0 : if($sd["Anzahl"] > 0){
99 0 : $anzahl = $anzahl + $sd["Anzahl"];
100 0 : }
101 0 : }
102 :
103 0 : echo "<table class='contentTable'>"."<tr><td class='tableHead'>Folgende Styles sind verfügbar</td></tr>".
104 0 : "<tr><td class='tableCell'>"."<p>Klicken Sie zum Übernehmen eines Styles auf dessen Namen oder den Screenshot.<br />".
105 0 : "Die Änderungen werden sofort übernommen und für den nächsten Login gespeichert.<br />".
106 0 : "Der Spalte Anzahl können Sie entnehmen, zu welchem Anteil dieser Style von anderen Usern,<br />".
107 0 : "die sich bewusst für einen Style entschieden haben, genutzt wird.<br />".
108 0 : "Anzahl der User, die sich bewusst für einen Style entschieden haben: ".$anzahl.".<br />".
109 0 : "Anzahl der User, die noch keinen Style gewählt haben: ".$basicUser.".<br />".
110 0 : "Hier können Sie den Portal <a href='index.php?setStyle=".$settings['style']."'>Standard Style</a> benutzen.</p>";
111 0 : echo "<table style='width:100%;' class='tableBorder'>"."<tr>"."<td class='tableHead'>Screenshot</td>"."<td class='tableHead'>Name</td>"."<td class='tableHead'>Autor</td>"."<td class='tableHead'>Datum</td>"."<td class='tableHead'>Beschreibung</td>"."<td class='tableHead'>Anzahl</td>"."</tr>";
112 : /* Wieviele Styles insgesamt? */
113 0 : $count = count($StylesData);
114 : /* Wie oft wurde ueberhaupt ein Style gew�hlt und nicht einfach der Standard benutzt? */
115 0 : $anzahl = 0;
116 0 : foreach($StylesData as $sd){
117 0 : if($sd["Anzahl"] > 0){
118 0 : $anzahl = $anzahl + $sd["Anzahl"];
119 0 : }
120 0 : }
121 :
122 0 : for ($i = 0 ; $i < $count ; $i++) {
123 0 : if (isset($_SESSION['UserStyle']) && $StylesData[$i][0] == $_SESSION['UserStyle']) $styleclass = "tableCellSelected";
124 0 : else if ($i%2 == 0) $styleclass = "tableCell";
125 0 : else $styleclass = "tableCellDark";
126 : /* Prozentanteil von aktuellem Style - ohne die Anzahl der User die keinen Style ausgewaehlt haben */
127 0 : $inProzent = ($anzahl != 0) ? ($StylesData[$i]["Anzahl"]*100/$anzahl) : 0;
128 : /* Ausgabe auf den Bildschirm */
129 : echo "<tr style='vertical-align: top;'>".
130 0 : "<td class='$styleclass'>".(file_exists($StylesData[$i][0]."/screenshot.png") ? "<a href='index.php?setStyle=".$StylesData[$i][0]."' title='Diesen Style übernehmen!'><img src='".$StylesData[$i][0]."/screenshot.png' height='90' width='120' alt='Screenshot ".$StylesData[$i][1]."' /></a>" : "") ."</td>".
131 0 : "<td class='$styleclass'><a href='index.php?setStyle=".$StylesData[$i][0]."' title='Diesen Style übernehmen!'>".Data::toHTML($StylesData[$i][1], false) ."</a></td>".
132 0 : "<td class='$styleclass'>".Data::toHTML($StylesData[$i][2], false) ."</td>".
133 0 : "<td class='$styleclass'><span style='font-size:smaller'>".Data::toHTML($StylesData[$i][3], false) ."</span></td>".
134 0 : "<td class='$styleclass'><span style='font-size:smaller'>".Data::toHTML($StylesData[$i][4], false) ."</span></td>".
135 0 : "<td class='$styleclass'><div class='percent_bar' style='width: ".round($inProzent) ."px;'></div><br /> ".sprintf("%.0f", $inProzent) ." % <br />(".$StylesData[$i]["Anzahl"]." von ".$anzahl.")</td>".
136 0 : "</tr>";
137 0 : }
138 0 : echo "</table>";
139 0 : echo "</td></tr></table>";
140 0 : }
141 : /**
142 : * Setzt das Style-Template in der Datenbank
143 : *
144 : * @access public
145 : * @param string $style Style-Name
146 : * @return string Aktueller Style
147 : */
148 : function setStyleTemplate($style) {
149 0 : global $db, $EZSQL_ERROR;
150 0 : $isStyle = false;
151 0 : foreach(Style::getStyleTemplates() as $template) {
152 0 : if ($template[0] == $style) {
153 0 : $isStyle = true;
154 0 : break;
155 : }
156 0 : }
157 0 : if ($isStyle) {
158 0 : $db->query("UPDATE user SET styletemplate='$style' WHERE ID='".$_SESSION['userid']."'");
159 0 : } else return "basic_css";
160 0 : return $style;
161 : }
162 : /**
163 : * Holt den gespeicherten Style des Users aus der Datenbank und schreibt ihn in die Session.
164 : * Falls der Benutzer die Verwendung des portalweit definierten barrierearmen Styles eingestellt
165 : * hat, wird dieser bevorzugt geladen.
166 : *
167 : * @access public
168 : * @return void
169 : */
170 : function setStyleTemplateFromDB() {
171 0 : global $db, $EZSQL_ERROR, $settings;
172 0 : unset($_SESSION["UserStyle"]);
173 0 : $col = $db->get_row("SELECT styletemplate, style_overwrite_mode FROM user WHERE ID='".$_SESSION["userid"]."'");
174 0 : $style = $col->styletemplate;
175 0 : if (empty($style)) {
176 : /* Kein Benutzer-Style, Portalstyle verwenden */
177 0 : $style = $settings['style'];
178 0 : }
179 0 : $styleOverwriteMode = (int)$col->style_overwrite_mode;
180 0 : if ($styleOverwriteMode == 2) {
181 : /* Barrierearmen Style verwenden */
182 0 : $style = $settings['accessible_style'];
183 0 : }
184 0 : if (!empty($style)) {
185 : //ist style directory vorhanden?
186 0 : if (file_exists(PATH_TO_ROOT."style/".$style."/_about.txt")) {
187 0 : $_SESSION['UserStyle'] = $style;
188 0 : }
189 0 : }
190 0 : }
191 : /**
192 : * Gibt den Pfad zur einzubindenen CSS-Datei zurück (ohne CSS-Datei, nur
193 : * das Verzeichnis). Entweder nach Benutzereinstellung, Portal-Einstellung
194 : * oder das Basic-CSS.
195 : *
196 : * @author Clemens Weiß <clemens.weiss@mni.fh-giessen.de>
197 : * @access public
198 : * @return string Relativer Pfad zur CSS-Datei
199 : */
200 : function getCSSPath() {
201 0 : global $settings;
202 0 : $path = PATH_TO_ROOT."style/%s/";
203 0 : $folder = "basic_css";
204 0 : if (!empty($settings["style"])) $folder = $settings["style"];
205 0 : if (!empty($_SESSION["UserStyle"])) $folder = $_SESSION["UserStyle"];
206 0 : if (!is_dir(sprintf($path, $folder))) $folder = "basic_css";
207 0 : return sprintf($path, $folder);
208 : }
209 :
210 : /**
211 : * Sortiert Array nach dem Anzahlfeld
212 : * @author Christoph Lhotak
213 : * @access public
214 : * @param array $array Das zu sortierende Array
215 : * @return Sortiertes Array
216 : */
217 : function sortiereArray($array){
218 : /**
219 : * Hilfsfunktion fuer usort
220 : * @author Christoph Lhotak
221 : * @param $a1, $a2 werden von usort uebergeben
222 : * @return usort kompatibler Wert
223 : */
224 0 : function cmp($a1, $a2){
225 0 : if($a1["Anzahl"] == $a2["Anzahl"])
226 0 : { return 0; }
227 0 : return ($a1["Anzahl"] < $a2["Anzahl"]) ? 1 : -1;
228 : }
229 0 : usort($array, "cmp");
230 0 : return $array;
231 : }
232 :
233 : }
|